
package com.wd.live.view.activity;




import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Toast;


import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.wd.live.model.utils.ToastFormat;
import com.wd.live.view.AgreementActivity;
import com.wd.live.view.PersonalDetails;
import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.base.BaseViewModel;
import com.wd.live.databinding.ActivityLoginBinding;
import com.wd.live.model.SpUtils;
import com.wd.live.wxapi.WXUtils;


public class LoginActivity extends BaseActivity<BaseViewModel, ActivityLoginBinding> {


    @Override
    protected void initData() {
databind.agreement.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(LoginActivity.this, AgreementActivity.class);
        startActivity(intent);
    }
});

databind.WXBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(databind.ck.isChecked()){
            boolean islogin = SpUtils.getBoolean("islogin", false);
            Log.v("islogin",islogin+"");
            if(islogin){
                Intent intent = new Intent(LoginActivity.this, PersonalDetails.class);
                startActivity(intent);
                finish();
            }
            if(WXUtils.success(LoginActivity.this)){
                SendAuth.Req req = new SendAuth.Req();
                req.scope = "snsapi_userinfo";
                req.state = "wx_login_duzun";
                WXUtils.reg(LoginActivity.this).sendReq(req);
            }else {
                ToastFormat.setText("您的设备未安装微信客户端");
                ToastFormat.show();
            }
        }else{
            ToastFormat.setText("请先勾选协议");
            ToastFormat.show();
        }



    }
});
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        boolean islogin = SpUtils.getBoolean("islogin", false);
        Log.v("islogin",islogin+"");
        if(islogin){
            Intent intent = new Intent(LoginActivity.this, PersonalDetails.class);
            startActivity(intent);
            finish();
        }
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void onChanged(Object o) {

    }
}